package com.wsc.wsckeeper.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.wsc.wsckeeper.R;
import com.wsc.wsckeeper.model.entity.CardTypeE;

public class CardsTypeAdapter extends ArrayAdapter<CardTypeE> {
	private List<CardTypeE> cardsType;
	private Context context;

	public CardsTypeAdapter(Context context, List<CardTypeE> cardsType) {
		super(context, android.R.layout.simple_spinner_item, cardsType);
		this.cardsType = cardsType;
		this.context = context;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View v = convertView;
		if (v == null) {
			LayoutInflater vi = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			v = vi.inflate(R.layout.adapter_item_simple_spiner, null);
		}

		CardTypeE item = cardsType.get(position);
		if (item != null) {
			TextView name = (TextView) v.findViewById(R.id.spinner_name);
			ImageView image = (ImageView) v.findViewById(R.id.spinner_image);
			name.setText(item.getDescription());
			image.setImageResource(item.getImage());

		}
		return v;
	}

	@Override
	public View getDropDownView(int position, View convertView, ViewGroup parent) {
		View v = convertView;
		if (v == null) {
			LayoutInflater vi = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			v = vi.inflate(R.layout.adapter_item_simple_spiner, null);
		}

		CardTypeE item = cardsType.get(position);
		if (item != null) {
			TextView name = (TextView) v.findViewById(R.id.spinner_name);
			ImageView image = (ImageView) v.findViewById(R.id.spinner_image);
			name.setText(item.getDescription());
			image.setImageResource(item.getImage());
		}
		return v;
	}

}